<%@include file="_header.jspf" %>
<%@page import="com.spartancoder.accommodation.beans.PlaceBean" %>
<%@page import="com.spartancoder.accommodation.models.Place" %>
<%@page import="java.util.List, java.util.LinkedList" %>
<%
   List<PlaceBean> placesList;
   String cId = request.getParameter("cid");
   String sId = request.getParameter("sid");
   if(cId !=null) {
       placesList = Place.fetchByCollege(Integer.parseInt(cId));
   } else if(sId != null) {
       placesList = Place.fetchByStudent(Integer.parseInt(sId));
   } else {
       placesList = Place.fetchAll();
   }
%>

<h2>Listare camine</h2>

<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Nume</th>
            <th>Adresa</th>
            <th>Camere</th>
            <th>Locuri per camera</th>
            <th>Stare</th>
            <th>Optiuni</th>
        </tr>
    </thead>
    <tbody>
    <% 
    int count = 0;
    for( PlaceBean pb : placesList ) { %>
        <tr <% if(count++ % 2 == 0) {%>class="odd"<%}else{%>class="even"<%}%>>
            <td><%=pb.getPlaceId()%></td>
            <td><%=pb.getName()%></td>
            <td><%=pb.getAddress()%></td>
            <td><%=pb.getRooms()%></td>
            <td><%=pb.getPlacesPerRoom()%></td>
            <td><% if(pb.isAvailable()) {%>
                Activ
                <% } else { %>
                Inactiv
                <% } %>
            </td
            <td>
            <a href="remove-place.jsp?id=<%=pb.getPlaceId()%>"
            onclick="return confirm('Esti sigur?')">sterge</a> -
            <a href="switch-place.jsp?id=<%=pb.getPlaceId()%>">
                <% if(pb.isAvailable()) {%>
                    dezactiveaza
                <% } else { %>
                    activeaza
                <% } %>
            </a>
        </td>

        </tr>
    <% } %>
    </tbody>
</table>

<%@include file="_footer.jspf" %>